package com.kkwrite.regimen.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * Created by lisha on 2018/7/7 13:10.
 *
 * @author lisha
 */
@SpringBootApplication
@ServletComponentScan
@EnableEurekaClient
@EnableHystrix
public class RegConsumerApp {
    private static final Logger logger = LoggerFactory.getLogger(RegConsumerApp.class);
    private static final String PROFILE_TYPE_DEV = "dev";
    private static final String PROFILE_TYPE_PRO = "pro";

    public static void main(String[] args) {
        String profile = PROFILE_TYPE_DEV;
        if (args != null && args.length > 0) {
            profile = args[0];
        }
        logger.info("服务器启动获取到的命令行参数profile：{}", profile);
        if (!profile.equals(PROFILE_TYPE_DEV) && !profile.equals(PROFILE_TYPE_PRO)) {
            logger.warn("profile参数配置有误，使用默认配置dev");
            profile = PROFILE_TYPE_DEV;
        }

        new SpringApplicationBuilder(RegConsumerApp.class)
                .profiles(profile)
                .run(args);
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
